<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/
defined('_JEXEC') or die('Restricted access'); 

$url	=	$mainframe->getSiteUrl()."/components/com_jl_project/assets/images/icons/profile/";

$editor =& JFactory::getEditor();

$row = $this->row;
JFilterOutput::objectHTMLSafe( $row, ENT_QUOTES, 'description' );
$cparams = JComponentHelper::getParams ('com_media');

?>
<script language="javascript" type="text/javascript">
function submitbutton(pressbutton) {
	var form = document.adminForm;
	if (pressbutton == 'cancel') {
		submitform( pressbutton );
		return;
	}
	if ((pressbutton == 'save')||(pressbutton == 'apply')) {
		if ( form.title.value == "" ) {
			alert("<?php echo JText::_( 'Subscription must have a title', true ); ?>");
			form.title.focus();
			return;
		}
		
		var cost =form.price.value;
		var numericExpression = /^[0-9]+$/;
		var numericExpression1 = /^[0-9]+\.[0-9]{1,2}$/;
		$submitform = 0;
		if ((cost == ""))
		{
			alert("<?php echo JText::_( 'Price could not be empty', true ); ?>");
			form.price.focus();
			return;
		}
		else 
		{
			if(cost !="")
			{
				if(cost.match(numericExpression)||cost.match(numericExpression1))
				{
					$submitform =1;
				}
				else
				{
					alert("<?php echo JText::_( 'Subscription price must be numeric', true ); ?>");
					form.price.focus();
					return;
				}
			}
			
		}
		duration = form.duration.value;
		if ((duration == ""))
		{
			alert("<?php echo JText::_( 'Subscription must have a duration', true ); ?>");
			form.duration.focus();
			return;
		}
		if(duration !="")
		{
//			if(duration.match(numericExpression)||duration.match(numericExpression1)||(duration=='-1'))
			if(!isNaN(duration))
			{
				$submitform =1;
			}
			else
			{
				alert("<?php echo JText::_( 'Subscription duration must be numeric', true ); ?>");
				form.duration.focus();
				return;
			}
		}
		qty = form.qty.value;
		if(qty !="")
		{
			if(qty.match(numericExpression)||qty.match(numericExpression1) || (qty =='-1'))
			{
				$submitform =1;
			}
			else
			{
				alert("<?php echo JText::_( 'Posting quantity must be numeric', true ); ?>");
				form.qty.focus();
				return;
			}
		}
		
		if($submitform ==1)
		{
			submitform(pressbutton);
			
		}
		
	}
	else {
		<?php
		echo $editor->save( 'description' ) ; 
		?>
		submitform(pressbutton);
	}
}
function RemoveImage(filename,type,controller,id){
	$('showimg').innerHTML = "";
	$('remove_img').value = 1;
}
</script>
		
<form name="adminForm" action="index.php" method="post" enctype="multipart/form-data">

	<table width="100%">
	<tr>
	
		<td width="80%" valign="top" align="left">
		
		    <div style="width:100%;">
				<fieldset class="adminform">
					<legend><?php echo JText::_( 'Subscription Details' ); ?></legend>
						<table class="admintable">
						<tr>
							<td class="key">
								<label for="title" width="100">
									<?php echo JText::_( 'Title' ); ?>:					
								</label>
								<br />
								<small>
									<?php echo JText::_('Will be displayed to user');?>
								</small>
							</td>
							<td colspan="2">
								<input class="text_area" type="text" name="title" id="title" value="<?php echo $row->title; ?>" size="50" maxlength="50" title="<?php echo JText::_( 'A long name to be displayed in headings' ); ?>" />								
								<font color="Red">*</font>
							</td>
						</tr>
						<!--<tr>
							<td class="key">
								<label for="image">
									<?php echo JText::_( 'Image' ); ?>:							</label>										</td>
							<td>
							<input type="file" name="img_sub" id="img_sub">
							<?php
							 if($row->image)
								{
									?>
								<span id="showimg">									
									<img width="50" src="<?php echo $mainframe->getSiteUrl()."/components/{$this->option}/images/icons/subscriptions/".$row->image?>" >
									<a onclick="RemoveImage('<?php echo $row->image?>','<?php echo $this->option?>','jasubscriptions',<?php echo $row->id ?>)" title="Remove this image"><img src="components/<?php echo $this->option;?>/images/icon_delete.gif" style="cursor:pointer"></a>
									
								</span>	
								<input type="hidden" name="remove_img" id="remove_img" value="0" /> 								
								<?php 
								}
								
							?>
							
							</td>
							</tr>-->
							<tr>
							<td width="120" class="key">
								<?php echo JText::_( 'Published' ); ?>:						</td>
							<td>
								<?php
								$published = ($row->id) ? $row->published : 1;
								$lists['published'] = JHTML::_('select.booleanlist',  'published', 'class="inputbox"', $published );
								 echo $lists['published']; ?>						
							</td>
						</tr>
						<!--<tr>
							<td width="120" class="key">
								<?php //echo JText::_( 'Require Approve' ); ?>:						</td>
							<td>
								<?php
								$require = ($row->id) ? $row->require_approved : 1;
								$lists['require'] 		= JHTML::_('select.booleanlist',  'require_approved', 'class="inputbox"', $require );
								 //echo $lists['require']; ?>						
								</td>
						</tr>-->
						<tr>
							<td valign="top" class="key">
								<label for="access">
									<?php echo JText::_( 'Duration' ); ?>:	
								</label>
								<br />
								<small><?php echo JText::_('Please enter subscription period for this product, it can also be set to lifetime or to fixed date. -1 for lifetime');?></small>
							</td>
							<td>
								<input type="text" value="<?php echo $row->duration; ?>" name="duration" id="duration"/>	
								<?php echo JText::_($this->units); ?>
								<font color="Red">*</font>
							</td>
						</tr>
						
						<tr>
							<td class="key">
								<label for="image">
									<?php echo JText::_( 'Price' ); ?>:	
								</label>
								<br/>
								<small><?php echo JText::_('Enter only digits (and period, if necessary).');?><small>
							</td>
							<td>
								<input class="text_area" type="text" name="price" id="price" value="<?php echo $row->price; ?>" size="50" maxlength="100"  />	
								(<?php if( $this->config['currency']->get('mode')=='special_currency' ){?>
									<?php echo $this->config['currency']->get('currency_symbol', 'credit');?> 
								<?php }else{?>
									<?php echo $this->config['currency']->get('currency', '$');?> 
								<?php }?>)
								<font color="Red">*</font>
							</td>
						</tr>
						<tr>
							<td class="key">
								<label for="subs_type">
									<?php echo JText::_('Subscription type' ); ?>
								</label>
							</td>
							<td>
								<?php
									
									$arr_subtype = JobBoardConstant::getSub_Type();
									$arr_value = array_keys($arr_subtype);
									$html = "<select id='subs_type' name='subs_type'>";		
																		
									foreach ($arr_value as $value)
										if ($row->subs_type!=$value)
											$html.="<option value='".$value."'>".$arr_subtype[$value]."</option>";
										else 
											$html.="<option selected='1' value='".$value."'>".$arr_subtype[$value]."</option>";
									$html.= "</select>";
									echo $html
								?>
							</td>
						</tr>
						<tr>
							<td class="key">
									<label for="qty">
										<?php echo JText::_( 'Posting quantity' ); ?>:
									</label>						
									<br/>
									<small><?php echo JText::_('THE NUMBER OF POST IS LICENSED WITH THIS SUBSCRIPTION. -1 FOR UNLIMITED');?></small>
							</td>
							<td>
								<input class="text_area" type="text" name="qty" id="qty" value="<?php echo $row->qty; ?>"  size="50" maxlength="100"  />
							</td>
						</tr>
						<tr>
							<td class="key">
									<label for="image_position">
										<?php echo JText::_( 'Permission' ); ?>:
									</label>						
									
									
							</td>
							<td>
								<?php echo $this->displayPermission;?>
							</td>
						</tr>
						<tr>
							<td class="key">
								<label for="image_position">
									<?php echo JText::_( 'Description' ); ?>:
								</label>						
								<br/>
								<small><?php echo JText::_('Will be displayed to user on signup page below the title');?></small>
							</td>
							<td valign="top" colspan="3">
								<?php
								// parameters : areaname, content, width, height, cols, rows, show xtd buttons
								echo $editor->display( 'description',  htmlspecialchars($row->description, ENT_QUOTES), '550', '200', '60', '20', array('pagebreak', 'readmore') ) ;
								?>
							</td>
						</tr>						
					</table>
				</fieldset>
				<br />
				<!--<fieldset class="adminform">
					<legend><?php echo JText::_( 'E-Mail Settings' ); ?></legend>
					<table class="admintable">
						<tr>
							<td class="key">
								<label for="title" width="150">
									<?php echo JText::_( 'Use Customized Signup E-Mail' ); ?>:					
								</label>
								<br />
								<small>
									<?php echo JText::_('use special e-mail message for this product');?>
								</small>
							</td>
							<td>
								<input type="checkbox" value="1" name="custom_signup_mail" id="custom_signup_mail" <?php if($row->custom_signup_mail) echo "checked";?>/>
								<a href="index.php?option=<?php echo $this->option; ?>&view=jaemail&task=edit&subscription_id=<?php echo $row->id; ?>&tpl=send_signup_mail">Edit E-Mail Template</a>
							</td>
						</tr>
						<tr>
							<td class="key">
								<label for="title" width="150">
									<?php echo JText::_( 'Use Customized Payment Receipt E-Mail' ); ?>:					
								</label>
								<br />
								<small>
									<?php echo JText::_('use special receitp e-mail message for this product. Send after the user purchase (not first signup)');?>
								</small>
							</td>
							<td>
								<input type="checkbox" value="1" name="custom_payment_mail" id="custom_payment_mail" <?php if($row->custom_payment_mail) echo "checked";?>/>
								<a href="index.php?option=<?php echo $this->option; ?>&view=jaemail&task=edit&subscription_id=<?php echo $row->id; ?>&tpl=send_payment_mail">Edit E-Mail Template</a>
							</td>
						</tr>
					</table>
				</fieldset>-->
				
			</div>
		</td>
	</tr>
	</table>
	<div class="clr"></div>
	<input type="hidden" name="image_old" value="<?php echo $old_image?>">
	<input type="hidden" name="option" value="<?php echo $this->option; ?>" />
	<input type="hidden" name="view" value="jasubscriptions" />
	<input type="hidden" name="oldtitle" value="<?php echo $row->title ; ?>" />
	<input type="hidden" name="id" value="<?php echo $row->id; ?>" />
	<input type="hidden" name="task" value="" />
	<?php echo JHTML::_( 'form.token' ); ?>	
</form>
<style type="text/css">
	table.admintable td.key{
		width:250px;
	}
</style>